package com.wuhenzhizao.sku.bean;

import ohos.utils.Parcel;
import ohos.utils.Sequenceable;

import java.util.List;

/**
 * SKuBean类
 *
 * @author wuhenzhizao
 * @since 2017-08-02
 */
public class Sku implements Sequenceable {
    /**
     * 反序列化
     */
    public static final Sequenceable.Producer CREATOR = new Producer<Sku>() {
        @Override
        public Sku createFromParcel(Parcel parcel) {
            Sku sku = new Sku();
            sku.unmarshalling(parcel);
            return sku;
        }
    };

    private String id;
    private String mainImage;
    private int stockQuantity;
    private boolean inStock;
    private long originPrice;
    private long sellingPrice;
    private List<SkuAttribute> attributes;

    /**
     * 构造
     */
    public Sku() {
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getMainImage() {
        return mainImage;
    }

    public void setMainImage(String mainImage) {
        this.mainImage = mainImage;
    }

    public int getStockQuantity() {
        return stockQuantity;
    }

    public void setStockQuantity(int stockQuantity) {
        this.stockQuantity = stockQuantity;
    }

    public boolean isInStock() {
        return inStock;
    }

    public void setInStock(boolean isInStock) {
        this.inStock = isInStock;
    }

    public long getOriginPrice() {
        return originPrice;
    }

    public void setOriginPrice(long originPrice) {
        this.originPrice = originPrice;
    }

    public long getSellingPrice() {
        return sellingPrice;
    }

    public void setSellingPrice(long sellingPrice) {
        this.sellingPrice = sellingPrice;
    }

    public List<SkuAttribute> getAttributes() {
        return attributes;
    }

    public void setAttributes(List<SkuAttribute> attributes) {
        this.attributes = attributes;
    }

    @Override
    public String toString() {
        return "Sku{"
                + "id='" + id + '\''
                + ", mainImage='" + mainImage + '\''
                + ", stockQuantity=" + stockQuantity
                + ", inStock=" + inStock
                + ", originPrice=" + originPrice
                + ", sellingPrice=" + sellingPrice
                + ", attributes=" + attributes
                + '}';
    }

    @Override
    public boolean marshalling(Parcel dest) {
        dest.writeString(this.id);
        dest.writeString(this.mainImage);
        dest.writeInt(this.stockQuantity);
        dest.writeByte(this.inStock ? (byte) 1 : (byte) 0);
        dest.writeLong(this.originPrice);
        dest.writeLong(this.sellingPrice);
        dest.writeSequenceableList(this.attributes);
        return true;
    }

    @Override
    public boolean unmarshalling(Parcel in) {
        this.id = in.readString();
        this.mainImage = in.readString();
        this.stockQuantity = in.readInt();
        this.inStock = in.readByte() != 0;
        this.originPrice = in.readLong();
        this.sellingPrice = in.readLong();
//        this.attributes = in.readSequenceableList(SkuAttribute.CREATOR);
        return true;
    }
}
